import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginchk")

public class LoginCheckServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // req
        // resp

        // 1. 接受用户请求信息
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        // 2. 业务处理
        String result = "";
        if("admin".equals(username)&&"123".equals(password))
        {
            result = "登录成功";
        }
        else
        {
            result = "登录失败";
        }

        // 3. 显示结果

        // 3.1 直接打印
//		resp.setContentType("text/html;charset=utf-8");
//		resp.getWriter().print(result);


        // 3.2 请求转发

        // 请求对象是一个域对象，把结果放在请求对象中
        req.setAttribute("result", result);
        // 请求转发jsp页面
        req.getRequestDispatcher("_5login_result.jsp").forward(req, resp);

    }
}
